#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;

int main() {
    deque<int> dq;

    dq.push_back(1);
    dq.push_back(3);
    dq.push_front(2);
    dq.push_back(20);
    for(int i = 0, len = dq.size(); i < len; ++i)
        cout << dq[i] << ",";
    cout << endl;

    sort(dq.begin(), dq.end());
    for(int i = 0, len = dq.size(); i < len; ++i)
        cout << dq[i] << ",";
    cout << endl;

    while(!dq.empty()) {
        cout << dq.front() << ",";
        cout << dq.back() << ",";
        dq.pop_front();
        dq.pop_back();
    }
    cout << endl;

    return 0;
}